/*
 * @author Chris
 * @since 2023/2/2 20:24
 *
 * @brief    The project will ...
 *
 * @note     ...
 *
 * @warning  Do not to ...
 *
 * Change Logs:
 *   Date           Author       Notes
 *   2023/2/2     Chris        the first version
 */

extern void InitLcd1602();

extern void Lcd1602Show(unsigned char x, unsigned char y, unsigned char *buf, unsigned char len);

extern void E2Read(unsigned char *buf, unsigned char addr, unsigned char len);

extern void E2Write(unsigned char *buf, unsigned char addr, unsigned char len);

void BytesToHexStr(unsigned char *src, unsigned char *dst, unsigned char len);

int main() {
    InitLcd1602();

    unsigned char buf[5];
    unsigned char str[20];

    E2Read(buf, 0x8E, sizeof(buf));
    BytesToHexStr(buf, str, sizeof(buf));
    Lcd1602Show(3, 1, str, 10);

    for (int i = 0; i < sizeof(buf); ++i) {
        buf[i] = buf[i] + 1 + i;
    }

    E2Write(buf, 0x8E, sizeof(buf));

    while (1);
}

void BytesToHexStr(unsigned char *src, unsigned char *dst, unsigned char len) {
    while (len--) {
        unsigned char tmp = *src >> 4;
        *dst++ = tmp > 9 ? tmp - 10 + 'A' : tmp + '0';

        tmp = *src & 0x0F;
        *dst++ = tmp > 9 ? tmp - 10 + 'A' : tmp + '0';

        src++;
    }
}
